/************************************************************************************
 * 原创：刘登
 * 
 * 联系邮箱：276155169@qq.com
 * 
 * 适用主板：智赛官方教学主板
 * 
 * 版权：版权归湖南智赛教育科技发展有限公司所有
 * 
 * 本程序库无偿供小学阶段普教学习使用，不得出售或有其他商业行为，违权必追。
 * 
 ********************************板载传感器与引脚说明**********************************
 * 
 * 主板集成2路直流电机驱动，一个启动按键，8个4P-RJ11端口
 * 
 * 2路电机端口：
 * MA：D4、D5
 * MB：D7、D6
 * 
 * 启动按键：D8//已删除

 * ==>RJ11端口：
 * A端口均为模拟引脚
 * A1：G、V、A0、A1
 * A2：G、V、A2、A3
 * A3：G、V、A6、A7
 * A4：G、V、A4、A5(IIC)
 * 
 * D端口均为数字引脚
 * D1：G、V、D3、D2
 * D2：G、V、D9、D8
 * D3：G、V、D10、D12
 * D4：G、V、D11、D13
 * D4：G、V、RX 0、TX 1(串口)
 * 
************************************************************************************/

/*--------------下拉参数--------------*/

/*--------------3P、4P、5P 引脚--------------*/

enum Pin_4 {
    //% block="D1"
    D1,
    //% block="D2"
    D2,
    //% block="D3"
    D3,
    //% block="D4"
    D4,
    //% block="A1"
    A1,
    //% block="A2"
    A2,
    //% block="A4 (IIC)"
    A4,
    //% block="串口（RX-TX)"
    D5,
    //% block="A3 (拓展专用)"
    A3,
}

enum Pin_A {
    //% block="A1"
    A1,
    //% block="A2"
    A2,
    //% block="A4 (IIC)"
    A4,
    //% block="A3 (拓展专用)"
    A3,
}

enum Pin_B {
    //% block="D1"
    D1,
    //% block="D2"
    D2,
    //% block="D3"
    D3,
    //% block="D4"
    D4,
    //% block="串口（RX-TX)"
    D5
}
/*Pin2*/
enum Pin_ZD {
    //% block="D1"
    D3
}
/*-------------------双路红外---------------*/
enum IR_Sensor {
    //% block="S1(左)"
    1,
    //% block="S2(右)"
    2
}

/*--------------数字传感器判断-------------*/
enum YOUWU {
    //% block="有信号"
    0,
    //% block="无信号"
    1
}

/*----------直流电机----------*/
enum DJ {
    //% block="M A"
    "MA",
    //% block="M B"
    "MB",
    //% block="ALL"
    "ALL"
}
/*----------直流电机停止----------*/
enum DJ_tz {
    //% block="全部直流电机"
    "ALL",
    //% block="M A"
    "MA",
    //% block="M B"
    "MB"
}
/*----------小车----------*/
enum XiaoChe_FX {
    //% block="前"
    1,
    //% block="后"
    2,
    //% block="左"
    3,
    //% block="右"
    4
}
/*----------直流电机误差调试----------*/
enum DJ1 {
    //% block="选择电机"
    "无",
    //% block="M A"
    "MA",
    //% block="M B"
    "MB"
}

/*----------扩展直流电机----------*/
enum PIN_KZDJ {
    //% block="D1"
    D1,
    //% block="D2"
    D2,
    //% block="D3"
    D3,
    //% block="D4"
    D4
}

/*----------按键----------*/
enum ANZHU {
    //% block="按住"
    1,
    //% block="松开"
    0
}
/*----------LED----------*/
enum liangmie {
    //% block="灭"
    0
    //% block="亮"
    1，
}

/*----------无源蜂鸣器----------*/
enum jiepai {
    //% block="1/2"
    500,
    //% block="1/4"
    250,
    //% block="1/8"
    125,
    //% block="整拍"
    1000,
    //% block="双拍"
    2000,
    //% block="停止"
    0,
}
enum BF_Music {
    //% block="警报"
    0,
    //% block="生日快乐"
    1,
    //% block="小跳蛙"
    2,
}
/*---------4位数码管显示----------*/
enum TM1637_caozuo {
    //% block="开"
    on,
    //% block="关"
    off,
    //% block="清屏"
    clear,
}


/*----------温湿度传感器----------*/
enum WenShiDu_DHT {
    //% block="DHT11"
    1,
    //% block="DHT22"
    2
}
enum WenShiDu {
    //% block="温度(℃)"
    getTemperature,
    //% block="湿度(%rh)"
    getHumidity
}

/*----------遥杆----------*/
enum joystick_XYZ {
    //% block="X轴"
    "X轴",
    //% block="Y轴"
    "Y轴"
    /*
    //% block="Z轴"
    "Z轴"
    */
}

/*----------模拟传感器----------*/
enum moni_shuru {
    //% block="环境光"
    1,
    //% block="声音"
    2,
    //% block="灰度"
    3,
    //% block="电位器"
    4,
    //% block="遥杆"
    5,
}

/*----------手势识别传感器----------*/
enum ShouShi_Pin {
    //% block="A4 IIC"
    A4
}
enum shou_shi{
    //% block="向上"
    DIR_UP,
    //% block="向下"
    DIR_DOWN,
    //% block="向左"
    DIR_LEFT,
    //% block="向右"
    DIR_RIGHT,
    //% block="逐渐靠近"
    DIR_NEAR,
    //% block="逐渐远离"
    DIR_FAR
}

/*----------颜色识别传感器----------*/
enum YanSe_Pin {
    //% block="A4 IIC"
    A4
}
enum YAN_SE {红色,绿色,蓝色}
enum RGB {
    R,G,B
}

/*---------红外遥控器按键-键值---------*/
enum hongwai_anjian {
    //% block="↑"
    16712445,
    //% block="↓"
    16750695,
    //% block="←"
    16769055,
    //% block="→"
    16748655,
    //% block="设置"
    16754775,

    //% block="A"
    16753245,
    //% block="B"
    16736925,
    //% block="C"
    16769565,
    //% block="D"
    16720605,
    //% block="E"
    16761405,
    //% block="F"
    16756815,

    //% block="0"
    16738455
    //% block="1"
    16724175,
    //% block="2"
    16718055,
    //% block="3"
    16743045,
    //% block="4"
    16716015,
    //% block="5"
    16726215,
    //% block="6"
    16734885,
    //% block="7"
    16728765,
    //% block="8"
    16730805,
    //% block="9"
    16732845
}



/*----------外部中断----------*/
enum Zhong_duan_PIN {2,3}
enum ZD_moshi {
    //% block="改变"
    CHANGE,
    //% block="上升"
    RISING,
    //% block="下降"
    FALLING
}

/*----------定时中断----------*/
enum dingshi_ZD_ZT {
    //% block="关闭（暂停）"
    1,
    //% block="开启（继续）"
    0
}


//% color="#3366FF" iconWidth=40 iconHeight=40  /*图标颜色#3078D8*/
namespace ZS_1
{
    //**************************************************//
    //--------------------输出设备----------------------//
    //*************************************************//
    
    //------------↓ 以下为输入设备 ↓------------------//

    //% block="↓ ------- 执 行 器 ------- ↓" blockType="hat"
    export function ZhiXingQi(parameter: any, block: any) { }

    /*空行*/
    //% block="---"
    export function kong_hang_001() { }

/*
    //--------------电机误差调试模块-------------------//
    
    //% block="电机误差调试[DJ1]加速/减速[WUCHA]" blockType="command"
    //% DJ1.shadow="dropdown" DJ1.options="DJ1" DJ1.defl="DJ1.1"
    //% WUCHA.shadow="range"   WUCHA.params.min=-100    WUCHA.params.max=100    WUCHA.defl=0
    export function Motor_WuCha(parameter: any, block: any) 
    {
        let DJ1 = parameter.DJ1.code;
        let WUCHA = parameter.WUCHA.code;

        Generator.addInclude('ZS_1', '#include <ZS_1.h>');//统一分类到ZS_1
        Generator.addObject( `Motor`, `DC_Motor`,`Motor;`);
        Generator.addSetup(`Motor.Init`,`Motor.Init();`);
        Generator.addCode(`Motor.WuCha(${DJ1},${WUCHA});`);
  
    }
*/

    //--------------电机模块-------------------//
    
    //% block="直流电机[DJ]速度[SUDU]" blockType="command"
    //% DJ.shadow="dropdown" DJ.options="DJ" DJ.defl="DJ.1"
    //% SUDU.shadow="range"   SUDU.params.min=-255    SUDU.params.max=255    SUDU.defl=100
    export function Motor(parameter: any, block: any) 
    {
        let DJ = parameter.DJ.code;
        let SUDU = parameter.SUDU.code;

        //Generator.addInclude('DC_Motor', '#include <DC_Motor.h>');//也可以使用
        Generator.addInclude('ZS_1', '#include <ZS_1.h>');//统一分类到ZS_1
        Generator.addObject( `Motor`, `DC_Motor`,`Motor;`);
        Generator.addSetup(`Motor.Init`,`Motor.Init();`);
        Generator.addCode(`Motor.MD(${DJ},${SUDU});`);
  
    }

    //--------------小车移动.前后左右-------------------//
    
    //% block="小车移动 [XiaoChe_FX]速度[XiaoChe_SUDU]" blockType="command"
    //% XiaoChe_FX.shadow="dropdown" XiaoChe_FX.options="XiaoChe_FX" XiaoChe_FX.defl="XiaoChe_FX.1"
    //% XiaoChe_SUDU.shadow="range"   XiaoChe_SUDU.params.min=0    XiaoChe_SUDU.params.max=255    XiaoChe_SUDU.defl=100
    export function XiaoChe_AB(parameter: any, block: any) 
    {
        let XiaoChe_FX = parameter.XiaoChe_FX.code;
        let XiaoChe_SUDU = parameter.XiaoChe_SUDU.code;

        //Generator.addInclude('DC_Motor', '#include <DC_Motor.h>');//也可以使用
        Generator.addInclude('ZS_1', '#include <ZS_1.h>');//统一分类到ZS_1
        Generator.addObject( `Motor`, `DC_Motor`,`Motor;`);
        Generator.addSetup(`Motor.Init`,`Motor.Init();`);
        if(XiaoChe_FX == 1)//前
        {
            Generator.addCode(`Motor.MD("MA",${XiaoChe_SUDU});`);
            Generator.addCode(`Motor.MD("MB",${XiaoChe_SUDU});`);
        }
        else if (XiaoChe_FX == 2)//后
        {
            Generator.addCode(`Motor.MD("MA",-${XiaoChe_SUDU});`);
            Generator.addCode(`Motor.MD("MB",-${XiaoChe_SUDU});`);
        }
        else if (XiaoChe_FX == 3)//左
        {
            Generator.addCode(`Motor.MD("MA",-${XiaoChe_SUDU});`);
            Generator.addCode(`Motor.MD("MB",${XiaoChe_SUDU});`);
        }
        else if (XiaoChe_FX == 4)//右
        {
            Generator.addCode(`Motor.MD("MA",${XiaoChe_SUDU});`);
            Generator.addCode(`Motor.MD("MB",-${XiaoChe_SUDU});`);
        }
  
    }

    //--------------电机模块MA+MB-------------------//
    
    //% block="左轮速度 (MA)[SUDU_MA]右轮速度 (MB)[SUDU_MB]" blockType="command"
    //% SUDU_MA.shadow="range"   SUDU_MA.params.min=-255    SUDU_MA.params.max=255    SUDU_MA.defl=100
    //% SUDU_MB.shadow="range"   SUDU_MB.params.min=-255    SUDU_MB.params.max=255    SUDU_MB.defl=100
    export function Motor_AB(parameter: any, block: any) 
    {
        let SUDU_MA = parameter.SUDU_MA.code;
        let SUDU_MB = parameter.SUDU_MB.code;

        //Generator.addInclude('DC_Motor', '#include <DC_Motor.h>');//也可以使用
        Generator.addInclude('ZS_1', '#include <ZS_1.h>');//统一分类到ZS_1
        Generator.addObject( `Motor`, `DC_Motor`,`Motor;`);
        Generator.addSetup(`Motor.Init`,`Motor.Init();`);
        Generator.addCode(`Motor.MD("MA",${SUDU_MA});`);
        Generator.addCode(`Motor.MD("MB",${SUDU_MB});`);
  
    }


    //--------------电机停止模块-------------------//

    //% block="停止[DJ_tz]" blockType="command"
    //% DJ_tz.shadow="dropdown" DJ_tz.options="DJ_tz" DJ_tz.defl="DJ_tz.1"
    export function Motor_TZ(parameter: any, block: any) 
    {
        let DJ_tz = parameter.DJ_tz.code;
        Generator.addInclude('ZS_1', '#include <ZS_1.h>');//统一分类到ZS_1
        Generator.addObject( `Motor`, `DC_Motor`,`Motor;`);
        Generator.addSetup(`Motor.Init`,`Motor.Init();`);
        Generator.addCode(`Motor.MD(${DJ_tz},0);`);
    }

    //--------------电机扩展模块-------------------//

    //% block="扩展直流电机[PIN_KZDJ]速度[SUDU]" blockType="command"
    //% PIN_KZDJ.shadow="dropdown" PIN_KZDJ.options="PIN_KZDJ" PIN_KZDJ.defl="PIN_KZDJ.1"
    //% SUDU.shadow="range"   SUDU.params.min=-255    SUDU.params.max=255    SUDU.defl=100
    export function Motor_KZ(parameter: any, block: any) 
    {
        let PIN_KZDJ = parameter.PIN_KZDJ.code;
        let SUDU = parameter.SUDU.code;

        //Generator.addInclude('DC_Motor', '#include <DC_Motor.h>');//也可以使用
        Generator.addInclude('ZS_1', '#include <ZS_1.h>');//统一分类到ZS_1
        Generator.addObject( `Motor_CD`, `DC_Motor_CD`,`Motor_CD;`);

        //引脚选择
        var Pin1,Pin2;
        if(PIN_KZDJ == "D1"){
            Pin1 = "3";
            Pin2 = "2";
        }
        else if(PIN_KZDJ == "D2"){
            Pin1 = "9";
            Pin2 = "8";
        }
        else if(PIN_KZDJ == "D3"){
            Pin1 = "10";
            Pin2 = "12";
        }
        else if(PIN_KZDJ == "D4"){
            Pin1 = "11";
            Pin2 = "13";
        }

        Generator.addSetup(`Motor_CD.Init`,`Motor_CD.Init(${Pin2},${Pin1});`);
        Generator.addCode(`Motor_CD.MD(${SUDU});`);
  
    }

    //--------------舵机模块-------------------//
    
    //% block="180° 舵机[Pin_4]角度[jiaodu]" blockType="command"

    //% Pin_4.shadow="dropdownRound" Pin_4.options="Pin_4" Pin_4.defl="Pin_4.1"
    //% jiaodu.shadow="angle"   jiaodu.params.edge=1
    export function SFMotor(parameter: any, block: any) 
    {
        let Pin_4 = parameter.Pin_4.code;
        let jiaodu = parameter.jiaodu.code;

        //Generator.addInclude('DFRobot_Servo', '#include <DFRobot_Servo.h>');
        Generator.addInclude('ZS_1', '#include <ZS_1.h>');//统一分类到ZS_1

        //引脚选择
        var Pin1,Pin2;
        if(Pin_4 == "A1"){
            Pin1 = "A0";
            Pin2 = "A1";
        }
        else if(Pin_4 == "A2"){
            Pin1 = "A2";
            Pin2 = "A3";
        }
        else if(Pin_4 == "A3"){
            Pin1 = "A6";
            Pin2 = "A7";
        }
        else if(Pin_4 == "A4"){
            Pin1 = "A4";
            Pin2 = "A5";
        }
        else if(Pin_4 == "D1"){
            Pin1 = "3";
            Pin2 = "2";
        }
        else if(Pin_4 == "D2"){
            Pin1 = "9";
            Pin2 = "8";
        }
        else if(Pin_4 == "D3"){
            Pin1 = "10";
            Pin2 = "12";
        }
        else if(Pin_4 == "D4"){
            Pin1 = "11";
            Pin2 = "13";
        }
        else if(Pin_4 == "D5"){
            Pin1 = "0";
            Pin2 = "1";
        }
        
        Generator.addObject( `servo_${Pin1}`, `Servo`,`servo_${Pin1};`);
        Generator.addSetup(`servo_${Pin1}.attach`,`servo_${Pin1}.attach(${Pin1});`);
        Generator.addCode(`servo_${Pin1}.angle(abs(${jiaodu}));`);
    }

    //空行
    //% block="---"
    export function kong_hang_0011() { }


    //--------------蜂鸣器模块-------------------//

    //% block="蜂鸣器[Pin_4]播放音调[STR]节拍[jiepai]" blockType="command"

    //% Pin_4.shadow="dropdownRound" Pin_4.options="Pin_4" Pin_4.defl="Pin_4.1"
    //% STR.shadow="note" STR.defl=247
    //% jiepai.shadow="dropdownRound" jiepai.options="jiepai" jiepai.defl="jiepai.1"

    export function FMQ(parameter: any, block: any) 
    {
        let Pin_4 = parameter.Pin_4.code;
        let STR = parameter.STR.code
        let jiepai = parameter.jiepai.code

        //Generator.addInclude('DFRobot_Libraries', '#include <DFRobot_Libraries.h>');
        Generator.addInclude('ZS_1', '#include <ZS_1.h>');//统一分类到ZS_1
        Generator.addObject(`DFTone`, `DFRobot_Tone`, `DFTone;`);

        //引脚选择
        var Pin1,Pin2;
        if(Pin_4 == "A1"){
            Pin1 = "A0";
            Pin2 = "A1";
        }
        else if(Pin_4 == "A2"){
            Pin1 = "A2";
            Pin2 = "A3";
        }
        else if(Pin_4 == "A3"){
            Pin1 = "A6";
            Pin2 = "A7";
        }
        else if(Pin_4 == "A4"){
            Pin1 = "A4";
            Pin2 = "A5";
        }
        else if(Pin_4 == "D1"){
            Pin1 = "3";
            Pin2 = "2";
        }
        else if(Pin_4 == "D2"){
            Pin1 = "9";
            Pin2 = "8";
        }
        else if(Pin_4 == "D3"){
            Pin1 = "10";
            Pin2 = "12";
        }
        else if(Pin_4 == "D4"){
            Pin1 = "11";
            Pin2 = "13";
        }
        else if(Pin_4 == "D5"){
            Pin1 = "0";
            Pin2 = "1";
        }

        Generator.addCode(`DFTone.play(${Pin1},${STR},${jiepai});`);
    }
    //--------------蜂鸣器模块--音乐-----------------//

    //% block="蜂鸣器[Pin_4]播放音乐[BF_Music]" blockType="command"

    //% Pin_4.shadow="dropdownRound" Pin_4.options="Pin_4" Pin_4.defl="Pin_4.1"
    //% BF_Music.shadow="dropdownRound" BF_Music.options="BF_Music"

    export function FMQ_Music(parameter: any, block: any) 
    {
        let Pin_4 = parameter.Pin_4.code;
        let BF_Music = parameter.BF_Music.code

        //Generator.addInclude('DFRobot_Libraries', '#include <DFRobot_Libraries.h>');
        //Generator.addInclude('FMQ_Music', '#include <FMQ_Music.h>');
        Generator.addInclude('ZS_1', '#include <ZS_1.h>');//统一分类到ZS_1
        Generator.addObject(`DFTone`, `DFRobot_Tone`, `DFTone;`);

        //引脚选择
        var Pin1,Pin2;
        if(Pin_4 == "A1"){
            Pin1 = "A0";
            Pin2 = "A1";
        }
        else if(Pin_4 == "A2"){
            Pin1 = "A2";
            Pin2 = "A3";
        }
        else if(Pin_4 == "A3"){
            Pin1 = "A6";
            Pin2 = "A7";
        }
        else if(Pin_4 == "A4"){
            Pin1 = "A4";
            Pin2 = "A5";
        }
        else if(Pin_4 == "D1"){
            Pin1 = "3";
            Pin2 = "2";
        }
        else if(Pin_4 == "D2"){
            Pin1 = "9";
            Pin2 = "8";
        }
        else if(Pin_4 == "D3"){
            Pin1 = "10";
            Pin2 = "12";
        }
        else if(Pin_4 == "D4"){
            Pin1 = "11";
            Pin2 = "13";
        }
        else if(Pin_4 == "D5"){
            Pin1 = "0";
            Pin2 = "1";
        }

        if(BF_Music == 0)
        {
            Generator.addCode(`DFTone.play(${Pin1},Music_0[0][0],Music_0[0][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_0[1][0],Music_0[1][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_0[2][0],Music_0[2][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_0[3][0],Music_0[3][1]);`);    
        }
        if(BF_Music == 1)
        {

            Generator.addCode(`DFTone.play(${Pin1},Music_1[0][0],Music_1[0][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[1][0],Music_1[1][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[2][0],Music_1[2][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[3][0],Music_1[3][1]);`);   
            Generator.addCode(`DFTone.play(${Pin1},Music_1[4][0],Music_1[4][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[5][0],Music_1[5][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[6][0],Music_1[6][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[7][0],Music_1[7][1]);`); 
            Generator.addCode(`DFTone.play(${Pin1},Music_1[8][0],Music_1[8][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[9][0],Music_1[9][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[10][0],Music_1[10][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[11][0],Music_1[11][1]);`); 
            Generator.addCode(`DFTone.play(${Pin1},Music_1[12][0],Music_1[12][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[13][0],Music_1[13][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[14][0],Music_1[14][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[15][0],Music_1[15][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[16][0],Music_1[16][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[17][0],Music_1[17][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[18][0],Music_1[18][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[19][0],Music_1[19][1]);`);   
            Generator.addCode(`DFTone.play(${Pin1},Music_1[20][0],Music_1[20][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[21][0],Music_1[21][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[22][0],Music_1[22][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[23][0],Music_1[23][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[24][0],Music_1[24][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[25][0],Music_1[25][1]);`);
            
            Generator.addCode(`DFTone.play(${Pin1},Music_1[0][0],Music_1[0][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[1][0],Music_1[1][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[2][0],Music_1[2][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[3][0],Music_1[3][1]);`);   
            Generator.addCode(`DFTone.play(${Pin1},Music_1[4][0],Music_1[4][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[5][0],Music_1[5][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[6][0],Music_1[6][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[7][0],Music_1[7][1]);`); 
            Generator.addCode(`DFTone.play(${Pin1},Music_1[8][0],Music_1[8][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[9][0],Music_1[9][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[10][0],Music_1[10][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[11][0],Music_1[11][1]);`); 
            Generator.addCode(`DFTone.play(${Pin1},Music_1[12][0],Music_1[12][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[13][0],Music_1[13][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[14][0],Music_1[14][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[15][0],Music_1[15][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[16][0],Music_1[16][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[17][0],Music_1[17][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[18][0],Music_1[18][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[19][0],Music_1[19][1]);`);   
            Generator.addCode(`DFTone.play(${Pin1},Music_1[20][0],Music_1[20][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[21][0],Music_1[21][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[22][0],Music_1[22][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[23][0],Music_1[23][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[24][0],Music_1[24][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_1[25][0],Music_1[25][1]);`);

        }
        if(BF_Music == 2)
        {
            Generator.addCode(`DFTone.play(${Pin1},Music_2[0][0],Music_2[0][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[1][0],Music_2[1][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[2][0],Music_2[2][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[3][0],Music_2[3][1]);`);   
            Generator.addCode(`DFTone.play(${Pin1},Music_2[4][0],Music_2[4][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[5][0],Music_2[5][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[6][0],Music_2[6][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[7][0],Music_2[7][1]);`); 
            Generator.addCode(`DFTone.play(${Pin1},Music_2[8][0],Music_2[8][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[9][0],Music_2[9][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[10][0],Music_2[10][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[11][0],Music_2[11][1]);`); 
            Generator.addCode(`DFTone.play(${Pin1},Music_2[12][0],Music_2[12][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[13][0],Music_2[13][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[14][0],Music_2[14][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[15][0],Music_2[15][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[16][0],Music_2[16][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[17][0],Music_2[17][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[18][0],Music_2[18][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[19][0],Music_2[19][1]);`);   
            Generator.addCode(`DFTone.play(${Pin1},Music_2[20][0],Music_2[20][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[21][0],Music_2[21][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[22][0],Music_2[22][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[23][0],Music_2[23][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[24][0],Music_2[24][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[25][0],Music_2[25][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[26][0],Music_2[26][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[27][0],Music_2[27][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[28][0],Music_2[28][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[29][0],Music_2[29][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[30][0],Music_2[30][1]);`);
            Generator.addCode(`DFTone.play(${Pin1},Music_2[31][0],Music_2[31][1]);`);
            
        }
    }

    //--------------LED灯模块，数字-------------------//

    //% block="LED 灯[Pin_4]状态[liangmie]" blockType="command"
    //% Pin_4.shadow="dropdownRound" Pin_4.options="Pin_4" Pin_4.defl="Pin_4.1"
    //% liangmie.shadow="dropdownRound" liangmie.options="liangmie" liangmie.defl="liangmie.1"

    export function LED_SZ(parameter: any, block: any) 
    {
        let Pin_4 = parameter.Pin_4.code;//获取传进来的值
        let liangmie = parameter.liangmie.code;

        //引脚选择
        var Pin1,Pin2;
        if(Pin_4 == "A1"){
            Pin1 = "A0";
            Pin2 = "A1";
        }
        else if(Pin_4 == "A2"){
            Pin1 = "A2";
            Pin2 = "A3";
        }
        else if(Pin_4 == "A3"){
            Pin1 = "A6";
            Pin2 = "A7";
        }
        else if(Pin_4 == "A4"){
            Pin1 = "A4";
            Pin2 = "A5";
        }
        else if(Pin_4 == "D1"){
            Pin1 = "3";
            Pin2 = "2";
        }
        else if(Pin_4 == "D2"){
            Pin1 = "9";
            Pin2 = "8";
        }
        else if(Pin_4 == "D3"){
            Pin1 = "10";
            Pin2 = "12";
        }
        else if(Pin_4 == "D4"){
            Pin1 = "11";
            Pin2 = "13";
        }
        else if(Pin_4 == "D5"){
            Pin1 = "0";
            Pin2 = "1";
        }
            
        Generator.addInclude('ZS_1', '#include <ZS_1.h>');//统一分类到ZS_1
        Generator.addCode(`digitalWrite(${Pin1},${liangmie});`);
    }

    //--------------LED灯模块,模拟-------------------//

    //% block="LED 灯[Pin_4]亮度[liangdu]" blockType="command"
    //% Pin_4.shadow="dropdownRound" Pin_4.options="Pin_4" Pin_4.defl="Pin_4.1"
    //% liangdu.shadow="range"   liangdu.params.min=0    liangdu.params.max=255    liangdu.defl=255

    export function LED_MN(parameter: any, block: any) 
    {
        let Pin_4 = parameter.Pin_4.code;
        let liangdu = parameter.liangdu.code;

        //引脚选择
        var Pin1,Pin2;
        if(Pin_4 == "A1"){
            Pin1 = "A0";
            Pin2 = "A1";
        }
        else if(Pin_4 == "A2"){
            Pin1 = "A2";
            Pin2 = "A3";
        }
        else if(Pin_4 == "A3"){
            Pin1 = "A6";
            Pin2 = "A7";
        }
        else if(Pin_4 == "A4"){
            Pin1 = "A4";
            Pin2 = "A5";
        }
        else if(Pin_4 == "D1"){
            Pin1 = "3";
            Pin2 = "2";
        }
        else if(Pin_4 == "D2"){
            Pin1 = "9";
            Pin2 = "8";
        }
        else if(Pin_4 == "D3"){
            Pin1 = "10";
            Pin2 = "12";
        }
        else if(Pin_4 == "D4"){
            Pin1 = "11";
            Pin2 = "13";
        }
        else if(Pin_4 == "D5"){
            Pin1 = "0";
            Pin2 = "1";
        }

        Generator.addCode(`analogWrite(${Pin1},${liangdu});`);
    }

    //--------------四位数码管模块-------------------//

    //% block="TMI1637四位数码管[Pin_4]亮度[TM1637_LiangDu]显示[TM1637_XSZiFuChuan]" blockType="command"
    //% Pin_4.shadow="dropdownRound" Pin_4.options="Pin_4" Pin_4.defl="Pin_4.1"
    //% TM1637_LiangDu.shadow="number"  TM1637_LiangDu.defl="20"
    //% TM1637_XSZiFuChuan.shadow="string" TM1637_XSZiFuChuan.defl="0001"

    export function TM1637_xianshi(parameter: any, block: any) 
    {
        let Pin_4 = parameter.Pin_4.code;
        let TM1637_LiangDu = parameter.TM1637_LiangDu.code;
        let TM1637_XSZiFuChuan = parameter.TM1637_XSZiFuChuan.code;

        //引脚选择
        var Pin1,Pin2;
        if(Pin_4 == "A1"){
            Pin1 = "A0";
            Pin2 = "A1";
        }
        else if(Pin_4 == "A2"){
            Pin1 = "A2";
            Pin2 = "A3";
        }
        else if(Pin_4 == "A3"){
            Pin1 = "A6";
            Pin2 = "A7";
        }
        else if(Pin_4 == "A4"){
            Pin1 = "A4";
            Pin2 = "A5";
        }
        else if(Pin_4 == "D1"){
            Pin1 = "3";
            Pin2 = "2";
        }
        else if(Pin_4 == "D2"){
            Pin1 = "9";
            Pin2 = "8";
        }
        else if(Pin_4 == "D3"){
            Pin1 = "10";
            Pin2 = "12";
        }
        else if(Pin_4 == "D4"){
            Pin1 = "11";
            Pin2 = "13";
        }
        else if(Pin_4 == "D5"){
            Pin1 = "0";
            Pin2 = "1";
        }

        Generator.addInclude('SevenSegmentTM1637', '#include <SevenSegmentTM1637.h>');
       // Generator.addInclude('SevenSegmentExtended', '#include <SevenSegmentExtended.h>');
        Generator.addObject( `display`, `SevenSegmentTM1637`,`display(${Pin2},${Pin1});`);
        Generator.addSetup(`display.begin`,`display.begin();`);

        Generator.addCode(`display.setBacklight(${TM1637_LiangDu});`);

        Generator.addCode(`display.print(${TM1637_XSZiFuChuan});`);
    } 

    //% block="数码管[TM1637_caozuo]" blockType="command"
    //% TM1637_caozuo.shadow="dropdownRound" TM1637_caozuo.options="TM1637_caozuo" TM1637_caozuo.defl="TM1637_caozuo.clear"
    export function TM1637_CaoZuo(parameter: any, block: any) 
    {
        let TM1637_caozuo = parameter.TM1637_caozuo.code;
        Generator.addCode(`display.${TM1637_caozuo}();`);
    }

    //------------------------------------------------//
    //------------------输入设备----------------------//
    //-----------------------------------------------//

    //空行
    //% block="---"
    export function kong_hang_002() { }

    //------------↓ 以下为输入设备 ↓------------------//

    //% block="↓ ------- 传 感 器 ------- ↓" blockType="hat"
    export function shurushebei(parameter: any, block: any) {
    }

    //空行
    //% block="---"
    export function kong_hang_003() { }

    //--------------按键模块-------------------//

    //% block="按键[Pin_4]状态[ANZHU]" blockType="boolean"
    //% Pin_4.shadow="dropdownRound" Pin_4.options="Pin_4" Pin_4.defl="Pin_4.1"
    //% ANZHU.shadow="dropdown" ANZHU.options="ANZHU" ANZHU.defl="1"
    
    export function anjian(parameter: any, block: any) 
    {
        let Pin_4 = parameter.Pin_4.code;
        let ANZHU = parameter.ANZHU.code;

        //引脚选择
        var Pin1,Pin2;
        if(Pin_4 == "A1"){
            Pin1 = "A0";
            Pin2 = "A1";
        }
        else if(Pin_4 == "A2"){
            Pin1 = "A2";
            Pin2 = "A3";
        }
        else if(Pin_4 == "A3"){
            Pin1 = "A6";
            Pin2 = "A7";
        }
        else if(Pin_4 == "A4"){
            Pin1 = "A4";
            Pin2 = "A5";
        }
        else if(Pin_4 == "D1"){
            Pin1 = "3";
            Pin2 = "2";
        }
        else if(Pin_4 == "D2"){
            Pin1 = "9";
            Pin2 = "8";
        }
        else if(Pin_4 == "D3"){
            Pin1 = "10";
            Pin2 = "12";
        }
        else if(Pin_4 == "D4"){
            Pin1 = "11";
            Pin2 = "13";
        }
        else if(Pin_4 == "D5"){
            Pin1 = "0";
            Pin2 = "1";
        }

        Generator.addCode(`digitalRead(${Pin1}) == ${ANZHU}`);
    }

/*
    //--------------双路红外线巡线模块（数字信号）-------------------//待改

    //% block="读取 IR 巡线传感器[Pin_4][IR_Sensor]" blockType="boolean"
    //% Pin_4.shadow="dropdownRound" Pin_4.options="Pin_4" Pin_4.defl="Pin_4.1"
    //% IR_Sensor.shadow="dropdown" IR_Sensor.options="IR_Sensor" IR_Sensor.defl="1"
    
    export function Digital_hongwai(parameter: any, block: any) 
    {
        let Pin_4 = parameter.Pin_4.code;
        let IR_Sensor = parameter.IR_Sensor.code;

        //引脚选择
        var Pin1,Pin2;
        if(Pin_4 == "A1"){
            Pin1 = "A0";
            Pin2 = "A1";
        }
        else if(Pin_4 == "A2"){
            Pin1 = "A2";
            Pin2 = "A3";
        }
        else if(Pin_4 == "A3"){
            Pin1 = "A6";
            Pin2 = "A7";
        }
        else if(Pin_4 == "A4"){
            Pin1 = "A4";
            Pin2 = "A5";
        }
        else if(Pin_4 == "D1"){
            Pin1 = "3";
            Pin2 = "2";
        }
        else if(Pin_4 == "D2"){
            Pin1 = "9";
            Pin2 = "8";
        }
        else if(Pin_4 == "D3"){
            Pin1 = "10";
            Pin2 = "12";
        }
        else if(Pin_4 == "D4"){
            Pin1 = "11";
            Pin2 = "13";
        }
        else if(Pin_4 == "D5"){
            Pin1 = "0";
            Pin2 = "1";
        }

        if(IR_Sensor == 1)
        {
            Generator.addCode(`digitalRead(${Pin1})`); 
        }
        else if(IR_Sensor == 2)
        {
            Generator.addCode(`digitalRead(${Pin2})`);  
        }  
    }
*/
    //--------------双路红外线巡线模块（模拟信号）-------------------//

    //% block="读取 IR 巡线传感器[Pin_A][IR_Sensor]" blockType="reporter"
    //% Pin_A.shadow="dropdownRound" Pin_A.options="Pin_A" Pin_A.defl="Pin_A.1"
    //% IR_Sensor.shadow="dropdown" IR_Sensor.options="IR_Sensor" IR_Sensor.defl="1"
    
    export function Analog_hongwai(parameter: any, block: any) 
    {
        let Pin_A = parameter.Pin_A.code;
        let IR_Sensor = parameter.IR_Sensor.code;

        //引脚选择
        var Pin1,Pin2;
        if(Pin_A == "A1"){
            Pin1 = "A0";
            Pin2 = "A1";
        }
        else if(Pin_A == "A2"){
            Pin1 = "A2";
            Pin2 = "A3";
        }
        else if(Pin_A == "A3"){
            Pin1 = "A6";
            Pin2 = "A7";
        }
        else if(Pin_A == "A4"){
            Pin1 = "A4";
            Pin2 = "A5";
        }

        if(IR_Sensor == 1)
        {
            Generator.addCode(`analogRead(${Pin1})`); 
        }
        else if(IR_Sensor == 2)
        {
            Generator.addCode(`analogRead(${Pin2})`);  
        }  
    }

    //--------------读取 光线传感器-------------------//

    //% block="读取 光线传感器[Pin_A]数据" blockType="reporter"
    //% Pin_A.shadow="dropdownRound" Pin_A.options="Pin_A" Pin_A.defl="Pin_A.1"
    export function DQ_guangxian(parameter: any, block: any) 
    {
        let Pin_A = parameter.Pin_A.code;

        //引脚选择
        var Pin1,Pin2;
        if(Pin_A == "A1"){
            Pin1 = "A0";
            Pin2 = "A1";
        }
        else if(Pin_A == "A2"){
            Pin1 = "A2";
            Pin2 = "A3";
        }
        else if(Pin_A == "A3"){
            Pin1 = "A6";
            Pin2 = "A7";
        }
        else if(Pin_A == "A4"){
            Pin1 = "A4";
            Pin2 = "A5";
        }

        Generator.addCode(`analogRead(${Pin1})`);
    }

    //--------------读取 声音传感器-------------------//

    //% block="读取 声音传感器[Pin_A]数据" blockType="reporter"
    //% Pin_A.shadow="dropdownRound" Pin_A.options="Pin_A" Pin_A.defl="Pin_A.1"
    export function DQ_shengyin(parameter: any, block: any) 
    {
        let Pin_A = parameter.Pin_A.code;

        //引脚选择
        var Pin1,Pin2;
        if(Pin_A == "A1"){
            Pin1 = "A0";
            Pin2 = "A1";
        }
        else if(Pin_A == "A2"){
            Pin1 = "A2";
            Pin2 = "A3";
        }
        else if(Pin_A == "A3"){
            Pin1 = "A6";
            Pin2 = "A7";
        }
        else if(Pin_A == "A4"){
            Pin1 = "A4";
            Pin2 = "A5";
        }

        Generator.addCode(`analogRead(${Pin1})`);
    }

    //--------------读取 电位传感器-------------------//

    //% block="读取 旋钮电位器[Pin_A]数据" blockType="reporter"
    //% Pin_A.shadow="dropdownRound" Pin_A.options="Pin_A" Pin_A.defl="Pin_A.1"
    export function DQ_xuanniu(parameter: any, block: any) 
    {
        let Pin_A = parameter.Pin_A.code;

        //引脚选择
        var Pin1,Pin2;
        if(Pin_A == "A1"){
            Pin1 = "A0";
            Pin2 = "A1";
        }
        else if(Pin_A == "A2"){
            Pin1 = "A2";
            Pin2 = "A3";
        }
        else if(Pin_A == "A3"){
            Pin1 = "A6";
            Pin2 = "A7";
        }
        else if(Pin_A == "A4"){
            Pin1 = "A4";
            Pin2 = "A5";
        }

        Generator.addCode(`analogRead(${Pin1})`);
    }

    //--------------温湿度传感器模块-------------------//

    //% block="读取 DHT11[Pin_4][WenShiDu]" blockType="reporter"
    //% Pin_4.shadow="dropdownRound" Pin_4.options="Pin_4" Pin_4.defl="Pin_4.1"
    //% WenShiDu.shadow="dropdownRound" WenShiDu.options="WenShiDu" WenShiDu.defl="WenShiDu.getTemperature"
    export function WENSHIDU(parameter: any, block: any) 
    {
        let Pin_4 = parameter.Pin_4.code;
        let WenShiDu = parameter.WenShiDu.code;

        //引脚选择
        var Pin1,Pin2;
        if(Pin_4 == "A1"){
            Pin1 = "A0";
            Pin2 = "A1";
        }
        else if(Pin_4 == "A2"){
            Pin1 = "A2";
            Pin2 = "A3";
        }
        else if(Pin_4 == "A3"){
            Pin1 = "A6";
            Pin2 = "A7";
        }
        else if(Pin_4 == "A4"){
            Pin1 = "A4";
            Pin2 = "A5";
        }
        else if(Pin_4 == "D1"){
            Pin1 = "3";
            Pin2 = "2";
        }
        else if(Pin_4 == "D2"){
            Pin1 = "9";
            Pin2 = "8";
        }
        else if(Pin_4 == "D3"){
            Pin1 = "10";
            Pin2 = "12";
        }
        else if(Pin_4 == "D4"){
            Pin1 = "11";
            Pin2 = "13";
        }
        else if(Pin_4 == "D5"){
            Pin1 = "0";
            Pin2 = "1";
        }
        //Generator.addInclude('DFRobot_DHT', '#include <DFRobot_DHT.h>');
        Generator.addInclude('ZS_1', '#include <ZS_1.h>');//统一分类到ZS_1
        Generator.addObject( `dht11_${Pin1}`, `DFRobot_DHT`,`dht11_${Pin1};`);
        Generator.addSetup(`dht11_${Pin1}.begin`,`dht11_${Pin1}.begin(${Pin1},DHT11);`);
        Generator.addCode(`dht11_${Pin1}.${WenShiDu}()`);
    }

    //--------------超声波传感器模块-------------------//

    //% block="读取 超声波[Pin_4]距离(cm)" blockType="reporter"
    //% Pin_4.shadow="dropdownRound" Pin_4.options="Pin_4" Pin_4.defl="Pin_4.1"
    export function ChaoShengBo(parameter: any, block: any) 
    {
        let Pin_4 = parameter.Pin_4.code;

        //引脚选择
        var Pin1,Pin2;
        if(Pin_4 == "A1"){
            Pin1 = "A0";
            Pin2 = "A1";
        }
        else if(Pin_4 == "A2"){
            Pin1 = "A2";
            Pin2 = "A3";
        }
        else if(Pin_4 == "A3"){
            Pin1 = "A6";
            Pin2 = "A7";
        }
        else if(Pin_4 == "A4"){
            Pin1 = "A4";
            Pin2 = "A5";
        }
        else if(Pin_4 == "D1"){
            Pin1 = "3";
            Pin2 = "2";
        }
        else if(Pin_4 == "D2"){
            Pin1 = "9";
            Pin2 = "8";
        }
        else if(Pin_4 == "D3"){
            Pin1 = "10";
            Pin2 = "12";
        }
        else if(Pin_4 == "D4"){
            Pin1 = "11";
            Pin2 = "13";
        }
        else if(Pin_4 == "D5"){
            Pin1 = "0";
            Pin2 = "1";
        }

        //Generator.addInclude('DFRobot_URM10', '#include <DFRobot_URM10.h>');
        Generator.addInclude('ZS_1', '#include <ZS_1.h>');//统一分类到ZS_1
        Generator.addObject( `urm10`, `DFRobot_URM10`,`urm10;`);

        Generator.addCode(`urm10.getDistanceCM(${Pin1},${Pin2})`);
    }

    //--------------遥杆传感器-----------------//

    //% block="读取 遥杆[Pin_A][joystick_XYZ]数据" blockType="reporter"
    //% Pin_A.shadow="dropdownRound" Pin_A.options="Pin_A" Pin_A.defl="Pin_A.1"
    //% joystick_XYZ.shadow="dropdownRound" joystick_XYZ.options="joystick_XYZ" joystick_XYZ.defl="joystick_XYZ.1"

    export function joystick(parameter: any, block: any) 
    {
        let Pin_A = parameter.Pin_A.code;
        let joystick_XYZ = parameter.joystick_XYZ.code;

        //引脚选择
        var Pin1,Pin2;
        if(Pin_A == "A1"){
            Pin1 = "A0";
            Pin2 = "A1";
        }
        else if(Pin_A == "A2"){
            Pin1 = "A2";
            Pin2 = "A3";
        }
        else if(Pin_A == "A3"){
            Pin1 = "A6";
            Pin2 = "A7";
        }
        else if(Pin_A == "A4"){
            Pin1 = "A4";
            Pin2 = "A5";
        }

        //Generator.addInclude('joystick', '#include <joystick.h>');//也可以使用
        Generator.addInclude('ZS_1', '#include <ZS_1.h>');//统一分类到ZS_1

        Generator.addObject( `Joystick`, `joystick`,`Joystick;`);
        Generator.addSetup(`Joystick.Init`,`Joystick.Init(${Pin1},${Pin2});`);
        Generator.addCode(`Joystick.Read_xyz(${joystick_XYZ})`);
    }

    //--------------手势识别模块-------------------//

    //% block="初始化 手势识别传感器[ShouShi_Pin]" blockType="command"
    //% ShouShi_Pin.shadow="dropdownRound" ShouShi_Pin.options="ShouShi_Pin" ShouShi_Pin.defl="ShouShi_Pin.1"
    export function Shou_shi_int(parameter: any, block: any) 
    {
        let ShouShi_Pin = parameter.ShouShi_Pin.code;
        
        Generator.addInclude('Wire', '#include <Wire.h>');
        Generator.addInclude('ZS_1', '#include <ZS_1.h>');
        Generator.addObject( `SparkFun_APDS9960`, `SparkFun_APDS9960`,`apds = SparkFun_APDS9960();`);
        //Generator.addSetup(`attachInterrupt`,`attachInterrupt(0, isr_flag = 1, FALLING);`);//初始化中断
        Generator.addSetup(`apds.init`,`apds.init();`);  // 初始化APDS-9960(配置I2C和初始值)
        Generator.addSetup(`apds.enableGestureSensor`,`apds.enableGestureSensor(true);`);  // 开始运行APDS-9960手势传感器引擎
    }
    //% block="手势传感器 有数据可读？" blockType="boolean"
    export function Shou_shi_shujukedu(parameter: any, block: any) 
    {
        Generator.addCode(`apds.isGestureAvailable()`);
    }
    //% block="读取手势数据" blockType="reporter"
    export function Shou_shi_dushuju(parameter: any, block: any) 
    {
        
        Generator.addCode(`apds.readGesture()`);
    }
    //% block=" = [shou_shi]手势" blockType="reporter"
    //% shou_shi.shadow="dropdownRound" shou_shi.options="shou_shi" shou_shi.defl="shou_shi.DIR_UP"
    export function Shou_shi_dushoushi(parameter: any, block: any) 
    {
        let shou_shi = parameter.shou_shi.code;
        
        Generator.addCode(`${shou_shi}`);
    }

    //----------------颜色识别传感器模块-------------------//

    //% block="初始化 颜色传感器[YanSe_Pin]" blockType="command"
    //% YanSe_Pin.shadow="dropdownRound" YanSe_Pin.options="YanSe_Pin" YanSe_Pin.defl="YanSe_Pin.1"
    
    export function Yan_se_chushihua(parameter: any, block: any) 
    {
        let YanSe_Pin = parameter.YanSe_Pin.code;

        Generator.addInclude('ZS_1', '#include <ZS_1.h>');//统一分类到LBXQ
        Generator.addObject( `tcs34725`, `EM_TCS34725`,`tcs34725;`);
        Generator.addSetup(`tcs34725.begin`,`tcs34725.begin();`);
    }

    //% block="读取 颜色传感器[RGB]值" blockType="reporter"
    //% RGB.shadow="dropdownRound" RGB.options="RGB" RGB.defl="RGB.1"
    
    export function Yan_se_duqu_RGB(parameter: any, block: any) 
    {
        let RGB = parameter.RGB.code;
        switch(RGB)
        {
            case 'R':Generator.addCode(`tcs34725.getRedToGamma()`);break;
            case 'G':Generator.addCode(`tcs34725.getGreenToGamma()`);break;
            case 'B':Generator.addCode(`tcs34725.getBlueToGamma()`);break;
        }
    }
    //% block="颜色传感器 识别到[YAN_SE]精确度[YanSe_Jingque]" blockType="boolean"
    //% YAN_SE.shadow="dropdownRound" YAN_SE.options="YAN_SE" YAN_SE.defl="YAN_SE.1"
    //% YanSe_Jingque.shadow="range" YanSe_Jingque.params.min=0 YanSe_Jingque.params.max=50 YanSe_Jingque.defl=40
    export function Yan_se_shibie(parameter: any, block: any) 
    {
        let YAN_SE = parameter.YAN_SE.code;
        let YanSe_Jingque = parameter.YanSe_Jingque.code;
        switch(YAN_SE)
        {
            case '红色':Generator.addCode(`tcs34725.getRedToGamma()>${YanSe_Jingque}`);break;//30 //50更准
            case '绿色':Generator.addCode(`tcs34725.getGreenToGamma()>${YanSe_Jingque}`);break;//20
            case '蓝色':Generator.addCode(`tcs34725.getBlueToGamma()>${YanSe_Jingque}`);break;//30
        }
    }


    //空行
    //% block="---"
    export function kong_hang_004() { }

    //------------↓ 以下为遥控器 ↓------------------//

    //% block="↓ -------- 遥控器 -------- ↓" blockType="hat"
    export function Yaokongqi(parameter: any, block: any) { }

    //空行
    //% block="---"
    export function kong_hang_005() { }


    //--------------------红外遥控（集成接收引脚简化版）-------------------//

    //% block="红外遥控器[Pin_4]初始化" blockType="command"
    //% Pin_4.shadow="dropdownRound" Pin_4.options="Pin_4" Pin_4.defl="Pin_4.1"
    export function Hongwai_YK(parameter: any, block: any) 
    {
        let Pin_4 = parameter.Pin_4.code;

        //引脚选择
        var Pin1,Pin2;
        if(Pin_4 == "A1"){
            Pin1 = "A0";
            Pin2 = "A1";
        }
        else if(Pin_4 == "A2"){
            Pin1 = "A2";
            Pin2 = "A3";
        }
        else if(Pin_4 == "A3"){
            Pin1 = "A6";
            Pin2 = "A7";
        }
        else if(Pin_4 == "A4"){
            Pin1 = "A4";
            Pin2 = "A5";
        }
        else if(Pin_4 == "D1"){
            Pin1 = "3";
            Pin2 = "2";
        }
        else if(Pin_4 == "D2"){
            Pin1 = "9";
            Pin2 = "8";
        }
        else if(Pin_4 == "D3"){
            Pin1 = "10";
            Pin2 = "12";
        }
        else if(Pin_4 == "D4"){
            Pin1 = "11";
            Pin2 = "13";
        }
        else if(Pin_4 == "D5"){
            Pin1 = "0";
            Pin2 = "1";
        }

        Generator.addInclude('ZS_1', '#include <ZS_1.h>');//统一分类到ZS_1
        //Generator.addInclude('IRremote', '#include <IRremote.h>');
        Generator.addObject( `irrecv`, `IRrecv`,`irrecv(${Pin1});`);
        Generator.addObject( `results`, `decode_results`,`results;`);
        Generator.addSetup(`irrecv.enableIRIn`,`irrecv.enableIRIn();`);    
    }

    //% block="接收到IR信号？" blockType="boolean"
    export function Hongwai_PanDuan(parameter: any, block: any) 
    {
        Generator.addCode(`(irrecv.decode(&results))`);
    }

    //% block="红外遥控[hongwai_anjian]键 按下？" blockType="boolean"
    //% hongwai_anjian.shadow="dropdownRound" hongwai_anjian.options="hongwai_anjian" hongwai_anjian.defl="hongwai_anjian.1"
    export function Hongwai_AnJian(parameter: any, block: any) 
    {
        let hongwai_anjian = parameter.hongwai_anjian.code;

        /*
        Generator.addInclude('ZS_1', '#include <ZS_1.h>');//统一分类到ZS_1
        //Generator.addInclude('IRremote', '#include <IRremote.h>');
        Generator.addObject( `irrecv`, `IRrecv`,`irrecv(12);`);
        Generator.addObject( `results`, `decode_results`,`results;`);
        Generator.addSetup(`irrecv.enableIRIn`,`irrecv.enableIRIn();`);
        //（有信号？）&&（键值确认）
        Generator.addCode(`(irrecv.decode(&results)) && (results.value == ${hongwai_anjian})`);  
        */ 
        Generator.addCode(`(results.value == ${hongwai_anjian})`); 
    } 

    //% block="等待接收下一组IR信号" blockType="command"
    export function Hongwai_DengDai(parameter: any, block: any) 
    {
        Generator.addCode(`irrecv.resume();`);
    }  

    //% block="读取IR信号值" blockType="reporter"
    export function Hongwai_DuQu(parameter: any, block: any) 
    {
        Generator.addCode(`(results.value)`);
    }

    //空行
    //% block="---"
    export function kong_hang_006() { }

    //------------↓ 以下为拓展功能 ↓------------------//

    //% block="↓ -------- 拓  展 -------- ↓" blockType="hat"
    export function TuoZhan(parameter: any, block: any) { }

    //空行
    //% block="---"
    export function kong_hang_007() { }

    //--------------硬件中断-------------------//
    //% block="硬件中断[Pin_ZD]模式[ZD_moshi]" blockType="hat"
    //% Pin_ZD.shadow="dropdown" Pin_ZD.options="Pin_ZD" Pin_ZD.defl="Pin_ZD.1"
    //% ZD_moshi.shadow="dropdown" ZD_moshi.options="ZD_moshi" ZD_moshi.defl="ZD_moshi.1"
    export function yingjian_ZD(parameter: any, block: any) {
        let Pin_ZD = parameter.Pin_ZD.code;
        let ZD_moshi = parameter.ZD_moshi.code;

        //引脚选择
        var Pin2;
        if(Pin_ZD == "D2"){
            Pin2 = '2';
        }
        else if(Pin_ZD == "D3"){
            Pin2 = '3';
        }

        Pin2 = replace(Pin2);
        ZD_moshi = replace(ZD_moshi);
        let name = 'attachInterrupt_fun_' + ZD_moshi + '_' + Pin2;
      
        Generator.addEvent(name, "void", name, "", true);
        Generator.addSetup(`pinMode_${Pin2}`,`pinMode(${Pin2}, INPUT_PULLUP);`);
        Generator.addSetup(`attachInterrupt_${Pin2}`,`attachInterrupt(digitalPinToInterrupt(${Pin2}),attachInterrupt_fun_${ZD_moshi}_${Pin2},${ZD_moshi});`);
        
    }
    function replace(str :string) {
        return str.replace("+", "");
    }
    //--------------硬件中断 专用延时-------------------//
    //% block="延时 [delay_ms]ms (中断专用)" blockType="command"
    //% delay_ms.shadow="range"   delay_ms.params.min=-10000    delay_ms.params.max=10000    delay_ms.defl=1000
    
    export function yingjian_ZD_delayMs(parameter: any, block: any) {
        let delay_ms = parameter.delay_ms.code;
        Generator.addInclude('ZS_1', '#include <ZS_1.h>');//统一分类到ZS_1
        Generator.addObject( `D`, `Delay_my`,`D;`);
        Generator.addCode(`D.Delay_ms(${delay_ms});`);
    }
    
    //--------------定时中断------------------//
    //% block="定时中断 间隔时间[Zd_shijian]秒" blockType="hat"
    //% Zd_shijian.shadow="number"  Zd_shijian.defl=0
    export function dingshi_ZD(parameter: any, block: any) 
    {
        let Zd_shijian = parameter.Zd_shijian.code;
        Zd_shijian = replace(Zd_shijian);

        let name = 'flash';

        //Generator.addInclude('MsTimer2', '#include <MsTimer2.h>');
        Generator.addInclude('ZS_1', '#include <ZS_1.h>');//统一分类到ZS_1
        Generator.addEvent(name, "void", name, "", true);
        Generator.addSetup(`MsTimer2::set`,`MsTimer2::set(${Zd_shijian}*1000, flash);`);
        Generator.addSetup(`MsTimer2::start`,`MsTimer2::start();`);
        
    }
    function replace(str :string) {

        return str.replace("+", "");
    }

    //--------------定时中断-状态------------------//
    //% block="[dingshi_ZD_ZT]定时中断" blockType="command"
    //% dingshi_ZD_ZT.shadow="dropdown" dingshi_ZD_ZT.options="dingshi_ZD_ZT" dingshi_ZD_ZT.defl="dingshi_ZD_ZT.1"
    export function dingshi_ZD_ZT(parameter: any, block: any) 
    {
        let dingshi_ZD_ZT = parameter.dingshi_ZD_ZT.code;

        if(dingshi_ZD_ZT == 1)
            Generator.addCode(`MsTimer2::stop();`);
        else
            Generator.addCode(`MsTimer2::start();`);
    }
}